// 基于准备好的dom，初始化echarts实例
var openChart = echarts.init(document.getElementById('openChart'));//开仓
var closeChart = echarts.init(document.getElementById('closeChart'));//平仓

// 指定图表的配置项和数据
var optionOpenChart = {
    tooltip: {
        trigger: 'axis',
        position: function (pt) {
            return [pt[0], '10%'];
        }
    },
    title: {
        left: 'center',
        text: '开仓差价走势图',
    },
    toolbox: {
        feature: {
            dataZoom: {
                yAxisIndex: 'none'
            },
            restore: {},
            saveAsImage: {}
        }
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: []
    },
    yAxis: {
        name: '差价百分比(%)',
        type: 'value',
        boundaryGap: [0, '100%']
    },
    dataZoom: [{
        type: 'inside',
        start: 60,
        end: 100
    }, {
        start: 0,
        end: 10,
        handleSize: '80%',
    }],
    series: [
        {
            name:'差价百分比',
            type:'line',
            smooth:true,
            symbol: 'none',
            sampling: 'average',
            itemStyle: {
                normal: {
                    color: 'rgb(255, 70, 131)'
                }
            },
            areaStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: 'rgb(255, 158, 68)'
                    }, {
                        offset: 1,
                        color: 'rgb(255, 70, 131)'
                    }])
                }
            },
            data: []
        }
    ]
};

// 指定图表的配置项和数据
var optionCloseChart = {
        tooltip: {
        trigger: 'axis',
        position: function (pt) {
            return [pt[0], '10%'];
        }
    },
    title: {
        left: 'center',
        text: '平仓差价走势图',
    },
    toolbox: {
        feature: {
            dataZoom: {
                yAxisIndex: 'none'
            },
            restore: {},
            saveAsImage: {}
        }
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: []
    },
    yAxis: {
        name: '差价百分比(%)',
        type: 'value',
        boundaryGap: [0, '100%']
    },
    dataZoom: [{
        type: 'inside',
        start: 60,
        end: 100
    }, {
        start: 0,
        end: 10,
        handleSize: '80%',
    }],
    series: [
        {
            name:'差价百分比',
            type:'line',
            smooth:true,
            symbol: 'none',
            sampling: 'average',
            itemStyle: {
                normal: {
                    color: 'rgb(255, 70, 131)'
                }
            },
            areaStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: 'rgb(255, 158, 68)'
                    }, {
                        offset: 1,
                        color: 'rgb(255, 70, 131)'
                    }])
                }
            },
            data: []
        }
    ]
};


$(document).ready(function () {
    $.get('data/result.json', { stamp: Math.random() }, function (data) {

        optionOpenChart.xAxis.data = data[0];
        optionOpenChart.series[0].data = data[1];

        optionCloseChart.xAxis.data = data[0]
        optionCloseChart.series[0].data = data[2];

        openChart.setOption(optionOpenChart);
        closeChart.setOption(optionCloseChart);
    });

});